package com.hengmei.smallscreen.adapter

import android.content.res.Resources
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.widget.LinearLayoutCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.hengmei.smallscreen.R
import com.hengmei.smallscreen.db.entity.HistoricalRecord
import com.inuker.bluetooth.library.search.SearchResult


class HistoryAdapter(layoutResId: Int, data: List<HistoricalRecord>?) :

    BaseQuickAdapter<HistoricalRecord, BaseViewHolder>(layoutResId,
        data as MutableList<HistoricalRecord>?
    ) {
    override fun convert(holder: BaseViewHolder, item: HistoricalRecord) {
        holder.setText(R.id.sample_name, item.sampleName)
        holder.setText(R.id.sample_code, item.projectName)
        holder.setText(R.id.temp_value, item.temp)
        holder.setText(R.id.water_value, item.waterContent+"%")
        var ll = holder.getView<LinearLayoutCompat>(R.id.ll_top)
        var sampleName = holder.getView<TextView>(R.id.sample_name)
        var sampleCode = holder.getView<TextView>(R.id.sample_code)
        var tempValue = holder.getView<TextView>(R.id.temp_value)
        var waterValue = holder.getView<TextView>(R.id.water_value)

        var position = getItemPosition(item)
//        计算取余  0
        if(position % 2 == 0){
            ll.setBackgroundResource(R.drawable.shape_list_radius)
            sampleName.setTextColor(context.resources.getColor(R.color.black))
            sampleCode.setTextColor(context.resources.getColor(R.color.black))
            tempValue.setTextColor(context.resources.getColor(R.color.black))
            waterValue.setTextColor(context.resources.getColor(R.color.black))
        }else{
            ll.setBackgroundResource(R.drawable.shape_round_white)
            sampleName.setTextColor(context.resources.getColor(R.color.black))
            sampleCode.setTextColor(context.resources.getColor(R.color.black))
            tempValue.setTextColor(context.resources.getColor(R.color.black))
            waterValue.setTextColor(context.resources.getColor(R.color.black))
        }

        if(item.space1 == "0"){
            ll.setBackgroundResource(R.drawable.shape_round_white)
            sampleName.setTextColor(context.resources.getColor(R.color.black))
            sampleCode.setTextColor(context.resources.getColor(R.color.black))
            tempValue.setTextColor(context.resources.getColor(R.color.black))
            waterValue.setTextColor(context.resources.getColor(R.color.black))
        }else{
            ll.setBackgroundResource(R.drawable.shape_select_blue)
            sampleName.setTextColor(context.resources.getColor(R.color.white))
            sampleCode.setTextColor(context.resources.getColor(R.color.white))
            tempValue.setTextColor(context.resources.getColor(R.color.white))
            waterValue.setTextColor(context.resources.getColor(R.color.white))
        }
    }


}
